function paging(page){
	    $("[name=page]").val(page);
$("#searchForm").submit();
}
    $(function(){
    	
    	
    	
    	
        $(".btn-danger").click(function(e){
        if(confirm("确定删除吗?"))
        {
            $.ajax({
                url:'/team/deleteById.json?id='+ e.currentTarget.id,
                type:'POST',
                dataType:"json",
                success:function(date) {
                    if(date.suc)
                    {
                        $(".close").click();
                        alert("删除成功！");
                        window.location.href = "/team/teamList.htm";
                    }else{
                       alert("删除有误！");
                        window.location.href = "/team/teamList.htm";
                    }
                }
            });
        }
    });
    
    $('.editTeamBT').click(function(e){
        e.preventDefault();
      //  $("#edit-receivableTime").val($("#invoice-receivableTime-"+e.currentTarget.id).val());
        $("#teamName").val($("#teamName-"+e.currentTarget.id).val());
        $("#edit-introduction").val($("#introduction-"+e.currentTarget.id).val());
        $("#edit-schoolId").val($("#schoolId-"+e.currentTarget.id).val());
        
        $("#edit_imgShow").attr("src",$("#logUrl-"+e.currentTarget.id).val());
        $("#edit-invitationCode").attr("value",$("#invitationCode-"+e.currentTarget.id).val());
        $('#id-input-file-2').ace_file_input({
            no_file: $("#logUrl-"+e.currentTarget.id).val(),
            btn_choose: 'Choose',
            btn_change: 'Change',
            droppable: false,
            onchange: null,
            thumbnail: false//| true | large
//                whitelist:'xls|xlsx'
            //blacklist:'exe|php'
            //onchange:''
        });
        
        $('#id-input-file-4').ace_file_input({
            no_file: $("#logUrl-"+e.currentTarget.id).val(),
            btn_choose: 'Choose',
            btn_change: 'Change',
            droppable: false,
            onchange: null,
            thumbnail: false//| true | large
//                whitelist:'xls|xlsx'
            //blacklist:'exe|php'
            //onchange:''
        });
        
        $("#edit-id").val(e.currentTarget.id);
        $('#editModel').modal('show');
    });
    
    
    
    $("#updateTeam").validate( {
        checkStart : true,
        errorElement: 'span',
        errorClass: 'help-inline',
        focusInvalid: false,
        rules : {
            name : {
                required: true
            },
            introduction : {
                required: true
            }
        },
        messages : {
            name : {
                required : "必须填写"
            },
            introduction : {
                required : "必须填写"
            }
        },
        submitHandler : function(form) {

            $("#updateTeam").ajaxSubmit(function(date,res,me){
                if(date.suc){
                    alert("修改成功了！");
                    $(".close").click();
                    window.location.href = "/team/teamList.htm";
                }else{
                	alert("修改失败了！");
                }
            });
        },
        highlight: function (e) {
            $(e).closest('.control-group').removeClass('info').addClass('error');
        }
    });
    
    $("#addTeam").validate( {
        checkStart : true,
        errorElement: 'span',
        errorClass: 'help-inline',
        focusInvalid: false,
        rules : {
            name : {
                required: true
            },
            introduction : {
                required: true
            }
        },
        messages : {
            name : {
                required : "必须填写"
            },
            introduction : {
                required : "必须填写"
            }
        },
        submitHandler : function(form) {
            $("#addTeam").ajaxSubmit(function(date,res,me){
                if(date.suc){
                    alert("保存成功了！");
                    window.location.href = "/team/teamList.htm";
                }else{
                	alert("添加失败！"+date.msg);
                }
            });
        },
        highlight: function (e) {
            $(e).closest('.control-group').removeClass('info').addClass('error');
        }
    });
    $(".btn-inverse").click(function(e){
        $("[name=page]").attr("value","1");
    });
    var options = {
            currentPage: $("[name=page]").val(),
            totalPages: $("[name=totalPage]").val(),
            alignment:"left",
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "末页";
                    case "page":
                        return page;
                }
            },
            pageUrl: function(type,page,current){
                return "javascript:paging('"+page+"');";
            }
        };
    $('#example').bootstrapPaginator(options);
    
    
    $('#id-input-file-1').ace_file_input({
        no_file: '没有文件 ...',
        btn_choose: 'Choose',
        btn_change: 'Change',
        droppable: false,
        onchange: null,
        thumbnail: false//| true | large
    });
    
    $('#id-input-file-3').ace_file_input({
        no_file: '没有文件 ...',
        btn_choose: 'Choose',
        btn_change: 'Change',
        droppable: false,
        onchange: null,
        thumbnail: false//| true | large
    });
    
   
});

function getCode(){
	var now= new Date(); 
	var year=now.getFullYear(); 
	var month=now.getMonth()+1; 
	var day=now.getDate(); 
	var hour=now.getHours(); 
	var minute=now.getMinutes(); 
	var second=now.getSeconds(); 
	var nowdate=year+""+month+day+hour+minute+second; 
	var invitationCode=nowdate+""+Math.round(Math.random()*10);
	$("#invitationCode").attr("value",invitationCode);
}